<#--
Default listener for the submit event for forms.
Note the implementation is slightly different than an anchor because the event's target may be a form.
 Parameters:
    clickListener  name of the listener function
    href           alternative URL (if not using the form's action)
    method         http method to use
    callback       name of the callback function (see YUI Connection Manager)
    customCallback if false, the default callback will be included

Javascript params:
  this     form element
  e        "submit" event
  sourceId  id of the button
-->
function ${parameters.clickListener}(e, sourceId) {
  if (e.type == 'submit') {
    if (sourceId == "${parameters.id}") {
      YAHOO.util.Event.preventDefault(e);  // prevent default submit if generated by this button
    }
  } else {
    var formObject;
    <#if parameters.href?exists>
    var href='${parameters.href}';
    <#else>
    var href = null;
    </#if>
    if (sourceId) {
       formObject = document.getElementById(sourceId);
    } else {
       formObject = YAHOO.util.Dom.getAncestorByTagName("${parameters.id}", 'FORM');
    }
    if ((formObject != null) && (formObject.tagName == 'FORM')) {
      YAHOO.util.Connect.setForm(formObject);
      <#if !parameters.href?exists>
      href=formObject.action;
      </#if>
    }
    if (href) {
      YAHOO.util.Connect.asyncRequest('${parameters.method}', href, ${parameters.callback});
    }
  }
}  
<#if !parameters.customCallback>
<#include "/${parameters.templateDir}/simple/default-callback.ftl" />
</#if>
